package D12_19z.BU_7;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

public class MyBeanUtils {
    public static Object populate(Class c, Map<String,Object[]> map) throws IllegalAccessException, InstantiationException, InvocationTargetException {
        Method[] methods = c.getMethods();
        Object o = c.newInstance();
        for (Map.Entry<String, Object[]> entry : map.entrySet()) {
            for (Method method : methods) {
                if (method.getName().contains("set"+entry.getKey().substring(0,1).toUpperCase()+entry.getKey().substring(1))){
                    method.invoke(o,entry.getValue());
                }
            }
        }
        return o;
    }
}
